using System;
using Scenario.WorkflowEngine.DataModel;

namespace Scenario.WorkflowEngine.DataModel.WorkflowProcesses
{	
	public class XMLBehaviourExecution : bOS.XML.Data.XMLObject
	{
		public const string MAIN_NODE				= "Execution";

		private const string MODE_ATTRIBUTE			= "Mode";
		private const string TYPE_ATTRIBUTE			= "Type";

		private const string REPORT_NODE			= "Report";

		public const string AUTOMATIC_MODE			= "AUTOMATIC";
		public const string MANUAL_MODE			= "MANUAL";

		public const string ROUTE_TYPE				= "ROUTE";
		public const string IMPLEMENTATION_TYPE	= "IMPLEMENTATION";
		public const string BLOCKACTIVITY_TYPE		= "BLOCKACTIVITY";

		private string sType;
		private string sMode;
		private string sReport;

		private XMLScript script;

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Width simple Property **/
		public XMLBehaviourExecution()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLBehaviourExecution(System.Xml.XmlNode node)
		{
			this.Parse(node);
		}

		/** PROPERTIES **/


		public XMLScript XMLScript 
		{
			get { return script; }
			set { script = value; }
		}

		public string Type 
		{
			get { return sType; }
			set { sType = value; }
		}

		public string Mode 
		{
			get { return sMode; }
			set { sMode = value; }
		}

		public string Report 
		{
			get { return sReport; }
			set { sReport = value; }
		}

		/** INSTANCE METHODS **/

		override public void Init()
		{
			sType = string.Empty;
			sMode = string.Empty;
			sReport = string.Empty;

			script = new XMLScript();


		}

		override public void Parse(System.Xml.XmlNode node2Parse)
		{
			this.Init();

			System.Xml.XmlNode node;

			
			/** find the attributes situated on the root tag **/
			for ( int i=0; i<node2Parse.Attributes.Count;i++)
			{
				node = node2Parse.Attributes.Item(i);

				switch ( node.Name )
				{
					case XMLBehaviourExecution.MODE_ATTRIBUTE:
						sMode = node.InnerText;
						break;
					case XMLBehaviourExecution.TYPE_ATTRIBUTE:
						sType = node.InnerText;
						break;
				}
			}

			/** find the sub tags witch contains values **/
			for ( int i=0; i<node2Parse.ChildNodes.Count; i++)
			{
				node = node2Parse.ChildNodes[i];

				switch ( node.Name )
				{
					case XMLBehaviourExecution.REPORT_NODE:
						sReport= node.InnerText;
						break;

					case XMLScript.MAIN_NODE:
						script.Parse(node);
						break;
				}
			}
		}

		override public bOS.XML.XMLNode GetXMLNode()
		{
			bOS.XML.XMLNode xmlNode = new bOS.XML.XMLNode(XMLBehaviourExecution.MAIN_NODE);
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute (XMLBehaviourExecution.MODE_ATTRIBUTE, sMode) );
			xmlNode.AddAttribute ( new bOS.XML.XMLAttribute (XMLBehaviourExecution.TYPE_ATTRIBUTE, sType) );
			
			xmlNode.AddNode ( script.GetXMLNode() );
			xmlNode.AddNode ( new bOS.XML.XMLNode (XMLBehaviourExecution.REPORT_NODE, sReport) );
			
			return xmlNode;
		}
	}
}
